package com.apps.utils;

import com.apps.sexctption.NullException;

public class EmailUtils {

    public static String EnCodeEmail(String email)
    {
        String[] s = email.split("@");
        if(s.length!=2)
            throw new NullException("这不是一个有效的邮箱地址");
        return EnCode(s[0],s[0].length()/2,"*")+"@"+s[1];
    }

    public static String EnCode(String s,int lenght,String symbol)
    {
        int startIndex = s.length()/2-lenght/2;
        int symbol_count=0;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i<s.length();i++){
            char number = s.charAt(i);
            if (i>=startIndex-1&&i<startIndex+lenght){
                stringBuilder.append(symbol_count<2?symbol:"");
                symbol_count++;
            }else {
                stringBuilder.append(number);
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String... args)
    {
        System.out.println(EnCodeEmail("459082139@qq.com"));
    }
}
